package chpt12;

/**
       首个DB测试程序，采用Statement
 */
import java.sql.*;

public class DBbasic1TryWithResources {
	public static void main(String[] args) {
		String dirverName = "com.mysql.cj.jdbc.Driver";
		String url = "jdbc:mysql://127.0.0.1:3306/demoDB?serverTimezone=Asia/Chongqing";
		String userName = "root";
		String pwd = "root123";
		String sql = "select * from students";
		try (Connection con = DriverManager.getConnection(url, userName, pwd);
				Statement stmt = con.createStatement();
				ResultSet rs = stmt.executeQuery(sql);) {
			while (rs.next()) {
				System.out.println("id=" + rs.getInt(1) +
						"; 学号=" + rs.getString(2) +
						"; 姓名=" + rs.getString("name") + 
						"; GPA=" + rs.getDouble(4)+
						"; 生日="+rs.getDate(5));
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}
}
